<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>门店分组</title>
		<link rel="stylesheet" href="../../../css/base.css" />
		<link rel="stylesheet" href="../../../css/common.css" />
		<link rel="stylesheet" type="text/css" href="store.css">
		<!-- Bootstrap Core CSS -->
		<link href="../../../sbadmin/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- MetisMenu CSS -->
		<link href="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
		<!-- DataTables CSS -->
		<link href="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
		<!-- Custom CSS -->
		<link href="../../../sbadmin/dist/css/sb-admin-2.css" rel="stylesheet">
		<!-- Custom Fonts -->
		<link href="../../../sbadmin/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	</head>

	<body style="background:#fff;">
		<div class="container-fluid" style="background-color: #fff;">
			<div class="title">
				<span style="font-weight: bold;">门店分组</span>
				<a href="addStore.html" class="create">新建</a>
			</div>
			<div class="bars-box">
				<div class="panel-body" style="padding-top: 0 !important;">
					<div class="dataTable_wrapper" id="app">
						<table class="table table-striped table-bordered table-hover" id="dataTables-example">
							<thead>
								<tr>
									<th>分组名称</th>
									<th>是否启用</th>
									<th>包含店面</th>
									<th>操作</th>
								</tr>
								<tbody id="list-td">

								</tbody>
							</thead>
						</table>
					</div>
					<!-- /.table-responsive -->
				</div>
				<!--<div class="no-tit">
        <img class="no-pic" src="../../../img/error.jpg" />
        <p class="no-txt">没有符合筛选条件的记录</p>
      </div>-->
			</div>

			<div class="delbox">
				<img class="tips" src="../../../img/del.png" />
				<div class="qbtn">
					<p class="cancel">取消</p>
					<p class="yest">确定</p>
				</div>
			</div>
			<div class="bgc"></div>
			<!-- jQuery -->
			<script src="../../../sbadmin/bower_components/jquery/dist/jquery.min.js"></script>
			<!-- Bootstrap Core JavaScript -->
			<script src="../../../sbadmin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
			<!-- Metis Menu Plugin JavaScript -->
			<script src="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.js"></script>
			<!-- DataTables JavaScript -->
			<script src="../../../sbadmin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
			<script src="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
			<!-- Custom Theme JavaScript -->
			<script src="../../..//sbadmin/dist/js/sb-admin-2.js"></script>
			<!-- Page-Level Demo Scripts - Tables - Use for reference -->
			<script src="../../../js/layer/layer.js"></script>
			<script type="text/javascript" src="../../../js/common.js"></script>
			<script type="text/javascript" src="../../../js/jquery-ui.min.js"></script>
	</body>
	<script>
		getList();

		function getList() {
			$("#dataTables-example").dataTable().fnDestroy();
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/storegroup/all",
				type: 'get',
				contentType: 'application/json',
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data)
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<tr class='odd gradeX'>";
							html += "<td>" + data.data[i].storeGroup.name + "</td>";
							if(data.data[i].storeGroup.status == "1") {
								html += "<td>是</td>";
							} else {
								html += "<td>否</td>";
							}
							html += "<td>";
							for(var j = 0; j < data.data[i].stores.length; j++) {
								html += "<label style='margin-right:5px;font-weight:normal;'>" + data.data[i].stores[j].name + "</label>";
							}
							html += "</td>";
							html += "<td><a href='updateStore.html' class='sDetail updateStore' name=" + data.data[i].storeGroup.name + " id='" + data.data[i].storeGroup.id + "'>编辑</a><a href='javascript:void(0);' class='sDetail DelBtn ml5' id='" + data.data[i].storeGroup.id + "'>删除</a></td>";
							html += "</tr>";
						}
						$("#list-td").html(html);
						$('#dataTables-example').DataTable({
							responsive: false,
							bLengthChange: false,
							bSort: true,
							paging: true,
							bFilter: true,
							searching: false,
							bInfo: true,
							bAutoWidth: true,
							"oLanguage": {
								"sLengthMenu": "每页显示 _MENU_ 条记录",
								"sZeroRecords": "抱歉， 没有找到",
								"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
								"sInfoEmpty": "没有数据",
								"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
								"oPaginate": {
									"sFirst": "首页",
									"sPrevious": "前一页",
									"sNext": "后一页",
									"sLast": "尾页"
								},
								"sSearch": "查询条件:",
								"sZeroRecords": "没有检索到数据",
								"sProcessing": "<img src='./loading.gif' />"
							}
						});
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}

				},
				error: function(e) {
					errcode(e);
				}
			});
		}
		$("#list-td").on("click", ".DelBtn", function() {
			var id = $(this).attr("id");
			layer.confirm('您确定删除吗？', {
				btn: ['确定', '取消'], //按钮
				offset: '25%'
			}, function(index) {
				$.ajax({
					url: "https://order.wz1996.wang/wzbg/storegroup/remove/" + id,
					type: 'DELETE',
					contentType: 'application/json',
					beforeSend: function(request) {
						request.setRequestHeader("token", localStorage.getItem("token"));
					},
					success: function(data) {
						console.log(data);
						//登录状态
						if(data.code == "1") {
							layar("删除成功");
							getList();
						} else if(data.code == "-1") {
							layar(data.msg);
							setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
						} else {
							layar(data.msg);
						}
					},
					error: function(e) {
						errcode(e);
					}
				});
			});
		})
		//存储id
		$("#list-td").on("click", ".updateStore", function() {
			var updateId = $(this).attr("id");
			var updateName = $(this).attr("name");
			localStorage.setItem("updateId", updateId);
			localStorage.setItem("updateName", updateName);
		})
	</script>

</html>